﻿/// <reference path="../master.js" />

Site.Lottery = {};
Site.Lottery.SingleMoney = 0;
Site.Lottery.BackMoneyToWinMoneyEnable = false;
Site.Lottery.BackMoneyToWinMoneyStep = 0.1;
Site.Lottery.SchemeItemIndex = 0;

Site.Lottery.Func = {};

/// <summary>
/// 当期的状态
/// </summary>
Site.IssueState = { Normal: 0, Opend: 1 };



/*************************************************************************************************************************************************************
**  投注控制
**************************************************************************************************************************************************************/

///	<summary>
///	购彩
///	</summary>
Site.Lottery.Play = function (lotteryid, lotteryname) {
    this.CurrentLottery.ID = lotteryid;
    this.CurrentLottery.Name = lotteryname;
    
    Site.Lottery.Bet = this;
};

///	<summary>
///	保存页面控件
///	</summary>
Site.Lottery.Play.WebUI = function() { };
Site.Lottery.Play.WebUI.prototype = {
    IssueID: null,               //用于提交 期号ID
    IssueName: null,             //显示当前期号
    ContDown: null,              //显示倒计时
    LastWin: null,               //显示上一期开奖号
    Schemes: [],                //显示方案的 <ul>
    Chases: [],                 //追号的 <ul>
    ChaseCbo: null,              //追号按扭
    SingleMultiply: null,        //不追号时的 倍数输入框
    StopWin: null,               //中奖后终止
    SumCount: null,              //显示总注数
    SumMoney: null,              //显示总金额
    SubmitBtn: null,             //认购的提交按扭
    BetListCount: 0,              //购买项数
    OpenCodeHistory: null,       //显示历史开奖号码
    
    BackMoneyToWinMoney: null       //返点加奖控件
};

Site.Lottery.Play.prototype = {
    CurrentLottery:{ ID: null, Name: null, ForwarEnd: 0 },
    CurrentIssue: null,

    ///	<summary>
    ///	上一期的内容
    ///	</summary>
    LastIssue: null,

    ///	<summary>
    ///	是否正在进行倒计时
    ///	</summary>
    IsTimeStart: false,

    Schemes: [],
    Chases: [],
    CurrentPlay: { ID: null, Name: null, Option: null },
    SumCount: 0,
    SumMoney: 0,
    SumMultiply: 0,
    IsChase: false,
    ChaseIssues: null,
    WinMoneyList: null,
    CanBet: false,
    UI: new Site.Lottery.Play.WebUI()
};

Site.Lottery.Bet = new Site.Lottery.Play();

Site.Lottery.Play.prototype.SetCurrentPlay = function (id, name) {
    this.CurrentPlay.ID = id;
    this.CurrentPlay.Name = name;

    this.CurrentPlay.Option = Site.Lottery.Bet.GetPlayTypeWinMoney(function (p) { return p.PlayTypeListID == Site.Lottery.Bet.CurrentPlay.ID; });

    Site.Lottery.Func.__BackMoneyToWinMoney_PlayTypeInit();
};
///	<summary>
///	添加一个投注项
///	</summary>
Site.Lottery.Play.prototype.AddPlayItem = function(playid, playname, number, count, args) {
    Site.Lottery.Bet.AddPlayItemNoRefresh(playid, playname, number, count, args);
    Site.Lottery.Func.__Schemes_Refresh_No();
};

///	<summary>
///	添加多个投注项
///	</summary>
Site.Lottery.Play.prototype.AddPlayItems = function(items) {
    if (!$.isArray(items))
        return;

    var nitems = [];

    for (var n in items) {
        var item = items[n];
        var flag = false;
        $.each(nitems, function(i, p) {
            if (item.playid == p.playid) {
                p.number += "; " + item.number;
                p.count += item.count;
                flag = true;
                return false;
            }
        });
        if (!flag)
            nitems.push(item);
    }

    window.setTimeout(function() {
        for (var n in nitems) {
            var item = nitems[n];
            Site.Lottery.Bet.AddPlayItemNoRefresh(item.playid, item.playname, item.number, item.count, item.args);
        }
        Site.Lottery.Func.__Schemes_Refresh_No();
    }, 10);
};

///	<summary>
///	添加投注项
///	</summary>
Site.Lottery.Play.prototype.AddPlayItemNoRefresh = function (playid, playname, number, count, args) {
    var id = '_' + (Site.Lottery.SchemeItemIndex++);
    var item = {
        PlayID: playid,
        PlayName: playname,
        Number: number,
        Count: count,
        Money: (count.mul(Site.Lottery.SingleMoney)), // * Site.Lottery.Bet.SumMultiply
        ID: id,
        WinMoneyType: args ? args : 1
    };
    //    Site.Lottery.Bet.Schemes[id] = item;

    if (Site.Lottery.BackMoneyToWinMoneyEnable) {
        var _ratioTo = Site.Lottery.Bet.UI.BackMoneyToWinMoney.find("#play_bet_backToWin_slider").slider("value");
        if (_ratioTo > 0) {
            item.BackMoneyToWinMoney = _ratioTo;
        }
    }

    var str = '<li class="item">' +
        '<span id="c1" class="span c1"><span>' + Site.Lottery.SchemeItemIndex + '.</span>' + item.PlayName + '</span>' +
        '<span id="c2" class="span c2">' + item.Number + '</span>' +
        '<span id="c3" class="span c3">' + item.Count + '注</span>' +
        '<span id="c4" class="span c4">￥' + item.Money + '</span>' +
        '<span id="c5" class="span c5">' + (item.BackMoneyToWinMoney ? (item.BackMoneyToWinMoney + '%') : '--') + '</span>' +
        '<span id="c6" class="span c6" title="删除">×</span>' +
        '<input type="hidden" id="play_bet_item" name="Bet.PlayList" value="' + item.PlayID + ':' + item.Number + ':' + args + ':' + (item.BackMoneyToWinMoney ? item.BackMoneyToWinMoney : '') +'" />' +
        '</li>';
    var docitem = $(str).data('play_item', item);
    docitem.find("#c6").click(function () {
        Site.Lottery.Func.__Schemes_item_del_click.call(this);
        Site.Lottery.Func.__Schemes_Refresh_No();
    });
    docitem.appendTo(Site.Lottery.Bet.UI.Schemes);
};

/// <summary>
/// 设置总注数
/// </summary>
Site.Lottery.Play.prototype.SetSumCount = function(num) {
    Site.Lottery.Bet.SumCount = num;
    Site.Lottery.Bet.UI.SumCount.html(Site.Lottery.Bet.SumCount + '注');

};
/// <summary>
/// 设置总金额
/// </summary>
Site.Lottery.Play.prototype.SetSumMoney = function(num) {
    num = num.add(0);
    Site.Lottery.Bet.SumMoney = num;
    Site.Lottery.Bet.UI.SumMoney.html('￥' + Site.Lottery.Bet.SumMoney.round(2));
    Site.Lottery.Bet.UI.SumMoney_Post.val(Site.Lottery.Bet.SumMoney.round(2) + "");
    Site.Lottery.Bet.UI.SumMoney_Post.valid();
};

///	<summary>
///	追号按钮单击事件
///	</summary>
Site.Lottery.Func.__ChaseCbo_click = function () {
    Site.Lottery.Bet.IsChase = this.checked;
    if (this.checked == true) {
        var issueid = Site.Lottery.Bet.UI.Chases.find('.head #start_issue').val();
        if (_ParseInt(issueid) == null)
            issueid = "";
        Site.Lottery.Bet.UI.IssueID.val(issueid);
        Site.Lottery.Bet.UI.StopWin.show();
        Site.Lottery.Bet.UI.SingleMultiply.parent().hide();
        Site.Lottery.Bet.UI.Chases.parent().show();
        Site.Lottery.Func.__Chases_title_startissue_change();
    } else {
        var issueid = Site.Lottery.Bet.CanBet ? Site.Lottery.Bet.CurrentIssue.IssueID : "";
        Site.Lottery.Bet.UI.IssueID.val(issueid);
        Site.Lottery.Bet.UI.StopWin.hide();
        Site.Lottery.Bet.UI.SingleMultiply.parent().show();
        Site.Lottery.Bet.UI.Chases.parent().hide();
        Site.Lottery.Bet.UI.SingleMultiply.change();
    }
    Site.Lottery.Bet.UI.IssueID.valid();
};

///	<summary>
///	追号栏选择所有
///	</summary>
Site.Lottery.Func.__Chases_title_chkall_click = function() {
    var checked = this.checked;
    var items = null;
    if (checked)
        items = Site.Lottery.Bet.UI.Chases.find(".empry .c1 :checkbox");
    else
        items = Site.Lottery.Bet.UI.Chases.find(".item .c1 :checkbox");
    items.each(function() {
        this.checked = checked;
        Site.Lottery.Func.__Chases_item_chk_click.call(this);
    });
};

///	<summary>
///	追号栏设置所有倍数
///	</summary>
Site.Lottery.Func.__Chases_title_multiply_change = function() {
    var value = _ParseInt(this.value);
    if (value == null || value < 1)
        this.value = 1;

    Site.Lottery.Bet.UI.Chases.find(".item .c3 :text").val(this.value)
        .each(function() {
            Site.Lottery.Func.__Chases_item_multiply_change.call(this);
        });
};

///	<summary>
///	追号栏设置追号期数
///	</summary>
Site.Lottery.Func.__Chases_title_chases_change = function() {
    var value = _ParseInt(this.value);
    if (value == null || value < 1)
        this.value = 1;

    Site.Lottery.Func.__Chases_title_startissue_set();
};

///	<summary>
///	追号栏设置追号期数
///	</summary>
Site.Lottery.Func.__Chases_title_startissue_set = function () {
    window.setTimeout(function () {
        var select = Site.Lottery.Bet.UI.Chases.find('.head #start_issue');
        Site.Lottery.Bet.UI.Chases.find(".item").each(function () {
            this.parentNode.removeChild(this);
        });
        Site.Lottery.Bet.UI.Chases.find(".empry").each(function () {
            this.parentNode.removeChild(this);
        });
        var value = _ParseInt(Site.Lottery.Bet.UI.Chases.find('.head #issue_count').val());
        var start = _ParseInt(select.val());
        if (start == null || value == null)
            return;
        var i = 0;
        for (; i < Site.Lottery.Bet.ChaseIssues.length; i++) {
            if (Site.Lottery.Bet.ChaseIssues[i].ID == start)
                break;
        }

        var isMul = Site.Lottery.Bet.UI.Chases.find('.head #chase_tool_no').is(":checked");
        var startIssueMul = _ParseInt(Site.Lottery.Bet.UI.Chases.find('.tool #tool_startMul').val());
        if (startIssueMul == null)
            startIssueMul = 1;
        var schemeItems = Site.Lottery.Bet.UI.Schemes.find(".item");
        var sumWinMoney = 0;
        if (schemeItems.length) {
            schemeItems.each(function () {
                var item = $(this);
                var data = item.data("play_item");
                var pwin = Site.Lottery.Bet.GetPlayTypeWinMoney(function (pitem) { return pitem.PlayTypeListID == data.PlayID });
                if (pwin != null) {
                    sumWinMoney = sumWinMoney.add(pwin.WinMoney);
                    if (data.BackMoneyToWinMoney)
                        sumWinMoney = sumWinMoney.add(pwin.BackMoneyToWinMoneyRatio.mul(data.BackMoneyToWinMoney));
                }
            });
        }
        var values = [];
        var tr = Site.Lottery.Bet.UI.Chases.find('.tool .active');
        values = tr.find('input').serializeArray();
        var k = 1;
        var summoney = 0;
        var schemeMoney = Site.Lottery.Bet.SumCount.mul(Site.Lottery.SingleMoney);
        for (var j = i; j < i + value && j < Site.Lottery.Bet.ChaseIssues.length; j++, k++) {
            var item = Site.Lottery.Bet.ChaseIssues[j];
            item.Multiply = 1;

            if (isMul) {
                //x = (全程利润率 / 100 * 累积投入 + 累积投入) / (奖金 - 方案金额 - 全程利润率 / 100 * 方案金额)
                var ratio = 0;
                switch (values[0].value) {
                    case '1':
                        ratio = _ParseInt(values[1].value);
                        break;
                    case '2':
                        if (k > 1 && k <= _ParseInt(values[1].value)) {
                            ratio = _ParseInt(values[2].value);
                        } else if (k > 1) {
                            ratio = _ParseInt(values[3].value);
                        }
                        break;
                    case '3':
                        break;
                    case '4':
                        break;
                }
                var num = sumWinMoney - schemeMoney - ratio / 100 * schemeMoney;
                if (num <= 0)
                    return;
                if (k > 1)
                    startIssueMul = Math.ceil((ratio / 100 * summoney + summoney) / num);

                item.Multiply = startIssueMul;
            }

            item.Money = item.Multiply.mul(Site.Lottery.Bet.SumCount).mul(Site.Lottery.SingleMoney);

            summoney = summoney.add(item.Money);
            if (summoney > 10000000) {
                break;
            }
            var tp = k.toString();
            while (tp.length < 3) {
                tp = "0" + tp;
            }
            var str = '<li class="item" issueid="' + item.ID + '">' +
                '<span id="c1" class="span c1"><label for="chases_item_c' + j + '_ckb_01">' + tp + '</label><input id="chases_item_c' + j + '_ckb_01" value="' + item.ID + '" type="checkbox" checked="checked" name="Bet.Chases" /></span>' +
                '<span id="c2" class="span c2"><label for="chases_item_c' + j + '_ckb_01">' + item.Number + '</label></span>' +
                '<span id="c3" class="span c3"><label ><input type="text" name="Bet.ChaseMultiply.' + item.ID + '" value="' + item.Multiply + '" class="text_small" />倍</label></span>' +
                '<span id="c4" class="span c4">￥' + (Site.Lottery.Bet.SumCount * Site.Lottery.SingleMoney).round(2) + '</span>' +
                '<span id="c5" class="span c5"/>' +
                '<span id="c6" class="span c6"/>' +
                '<span id="c7" class="span c7"/>' +
                '</li>';
            item.Money = Site.Lottery.Bet.SumCount.mul(Site.Lottery.SingleMoney);
            var doc = $(str).data('chase_item', item);
            doc.find("#c1 :checkbox").click(function () {
                Site.Lottery.Func.__Chases_item_chk_click.call(this);
                Site.Lottery.Func.__Chase_Refresh_No();
            });

            doc.find("#c3 :text").change(function () {
                Site.Lottery.Func.__Chases_item_multiply_change.call(this);
                Site.Lottery.Func.__Chase_Refresh_No();
            }).keypress(Site.Lottery.Func.__Text_CheckInt_keypress);

            doc.appendTo(Site.Lottery.Bet.UI.Chases);
        }
        if (j <= i + value) {
            Site.Lottery.Bet.UI.Chases.find('.head #issue_count').val(j - i);
        }
        if (Site.Lottery.Bet.UI.Chases.find(".item").length)
            Site.Lottery.Bet.UI.Chases.find(".empry").show();

        Site.Lottery.Func.__Chase_Refresh_No();
    }, 0);
};

///	<summary>
///	移除过期的追号期号
///	</summary>
Site.Lottery.Func.__Chases_RemoveTimeOutIssue = function(id) {
    var select = Site.Lottery.Bet.UI.Chases.find('.head #start_issue');
    select.find('option[value=' + id + ']').each(function() {
        this.parentNode.removeChild(this);
    });
    Site.Lottery.Bet.UI.Chases.find("li[issueid=" + id + "]").each(function() {
        this.parentNode.removeChild(this);
    });
    Site.Lottery.Func.__Chase_Refresh_No();
};

///	<summary>
///	追号栏设置追号期数
///	</summary>
Site.Lottery.Func.__Chases_title_startissue_change = function() {
    Site.Lottery.Func.__Chases_title_chases_change.call(Site.Lottery.Bet.UI.Chases.find('.head #issue_count')[0]);
};

///	<summary>
///	追号栏 选择项
///	</summary>
Site.Lottery.Func.__Chases_item_chk_click = function() {
    var item = $(this).parent().parent();
    var checked = this.checked;
    var data = item.data('chase_item');
    if (checked) {
        item.removeClass("empry");
        item.addClass("item");
        item.find("#c3 :text").removeAttr("disabled");

    } else {
        item.removeClass("item");
        item.addClass("empry");
        item.find("#c4,#c5,#c6,#c7").html("");
        item.find("#c3 :text").attr("disabled", "true");

    }
};

///	<summary>
///	追号栏 设置倍数
///	</summary>
Site.Lottery.Func.__Chases_item_multiply_change = function() {
    if (this.disabled)
        return;
    var value = _ParseInt(this.value);
    if (value == null || value < 1)
        this.value = 1;

};


///	<summary>
///	追号 刷新
///	</summary>
Site.Lottery.Func.__Chase_Refresh_No = function () {
    if (!Site.Lottery.Bet.IsChase)
        return;
    window.setTimeout(function () {
        var items = Site.Lottery.Bet.UI.Chases.find(".item");
        var schemeItems = Site.Lottery.Bet.UI.Schemes.find(".item")
        var summultiply = 0;
        var summoney = 0;
        var sumWinMoney = 0;
        if (schemeItems.length) {
            schemeItems.each(function () {
                var item = $(this);
                var data = item.data("play_item");
                var pwin = Site.Lottery.Bet.GetPlayTypeWinMoney(function (pitem) { return pitem.PlayTypeListID == data.PlayID });
                if (pwin != null) {
                    sumWinMoney = sumWinMoney.add(pwin.WinMoney);
                    if (data.BackMoneyToWinMoney)
                        sumWinMoney = sumWinMoney.add(pwin.BackMoneyToWinMoneyRatio.mul(data.BackMoneyToWinMoney));
                }
            });
        }
        if (items.length) {
            items.each(function () {
                var item = $(this);
                var data = item.data("chase_item");
                var txt = item.find('#c3 :text')[0];
                if (!txt || txt == null) {
                    txt = item.find('#c3 :text')[0];
                }
                data.Multiply = _ParseInt(txt.value);
                data.Money = data.Multiply.mul(Site.Lottery.Bet.SumCount).mul(Site.Lottery.SingleMoney);
                item.find('#c4').text('￥' + data.Money);
                item.data("chase_item", data);

                summoney = summoney.add(data.Money);
                if (summoney > 10000000) {

                }
                item.find('#c5').text("￥" + summoney.round(2));
                item.find('#c6').text("￥" + data.Multiply.mul(sumWinMoney).round(2));
                var str = sumWinMoney.mul(data.Multiply).sub(summoney).mul(100);
                if (summoney != 0) {
                    str = str.div(summoney);
                    str = str.toString().split('.')[0];
                    item.find('#c7').text(str + '%');
                } else
                    item.find('#c7').text('--');
                summultiply = summultiply.add(data.Multiply);
            });
        }
        if (Site.Lottery.Bet.IsChase) {
            Site.Lottery.Bet.SumMultiply = summultiply;
            Site.Lottery.Bet.SumMoney = summoney;
            Site.Lottery.Bet.SetSumMoney(summoney);
        }
    }, 0);
};
///<summary>
///生成投资计划表
///</summary>
Site.Lottery.Func.__GetPlayItem = function() {
    Site.Lottery.Func.__Chases_title_startissue_set();
};



///	<summary>
///	方案栏 删除所有
///	</summary>
Site.Lottery.Func.__Schemes_title_delall_click = function() {
    Site.Lottery.Bet.UI.Schemes.find(".item #c5").each(function() {
        Site.Lottery.Func.__Schemes_item_del_click.call(this);
    });
    Site.Lottery.Func.__Schemes_Refresh_No();
};

///	<summary>
///	方案栏 删除项
///	</summary>
Site.Lottery.Func.__Schemes_item_del_click = function() {
    var li = $(this).parent();
    var playitem = li.data("play_item");
    //    if (playitem) {
    //        Site.Lottery.Bet.SetSumCount(Site.Lottery.Bet.SumCount-playitem.Count)
    //        Site.Lottery.Bet.SetSumMoney(Site.Lottery.Bet.SumMoney-playitem.Money)
    //    }

    li[0].parentNode.removeChild(li[0]);
};

///	<summary>
///	方案栏 刷新
///	</summary>
Site.Lottery.Func.__Schemes_Refresh_No = function() {
    setTimeout(function() {
        var items = Site.Lottery.Bet.UI.Schemes.find(".item");
        var count = 0;
        var sumcount = 0;
        var summoney = 0;
        if (!items.length) {
            Site.Lottery.Bet.UI.Schemes.find(".empry").show();
        } else {
            count = items.length;
            Site.Lottery.Bet.UI.Schemes.find(".empry").hide();
            items.each(function(i) {
                var item = $(this);
                var data = item.data("play_item");
                //data.Money = data.Count * Site.Lottery.Bet.SumMultiply * Site.Lottery.SingleMoney;
                sumcount = sumcount.add(data.Count);
                summoney = summoney.add(data.Money);
                //item.find('#c4').text('￥' + data.Money);
                //item.find('#c1 span').text((i + 1) + '.');
                //item.data("play_item", data);

            });
        }
        Site.Lottery.Bet.SetSumCount(sumcount);
        Site.Lottery.Bet.UI.BetListCount.html(count);
        if (Site.Lottery.Bet.IsChase)
            Site.Lottery.Func.__Chase_Refresh_No();
        else {
            Site.Lottery.Bet.SetSumMoney(summoney * Site.Lottery.Bet.SumMultiply);
        }
    }, 0);
};

///	<summary>
///	单期方案 倍数
///	</summary>
Site.Lottery.Func.__Schemes_SingleMultiply_change = function () {
    var value = _ParseInt(this.value);
    if (value == null || value < 1)
        this.value = 1;

    value = _ParseInt(this.value);
    Site.Lottery.Bet.SumMultiply = value;
    Site.Lottery.Func.__Bet_Refresh_UI(); //__Schemes_Refresh_No();

};

///	<summary>
///	
///	</summary>
Site.Lottery.Func.__Bet_Refresh_UI = function() {
    Site.Lottery.Bet.SetSumMoney(Site.Lottery.Bet.SumCount * Site.Lottery.SingleMoney * Site.Lottery.Bet.SumMultiply);
};


///	<summary>
///	输入验证 整型
///	</summary>
Site.Lottery.Func.__Text_CheckInt_keypress = function(e) {
    if (!((e.keyCode > 46 && e.keyCode < 58) || e.keyCode == 13))
        return false;

    if (e.keyCode == 13) {
        e.keyCode = 9;
        this.blur();
        return false;
    }
};
///	<summary>
///	返点加奖 玩法初始化
///	</summary>
Site.Lottery.Func.__BackMoneyToWinMoney_PlayTypeInit = function () {

    var slider = Site.Lottery.Bet.UI.BackMoneyToWinMoney.find("#play_bet_backToWin_slider");

    if (!Site.Lottery.BackMoneyToWinMoneyEnable)
        return;
    
    slider.slider("option", "value", 0);

    if (!Site.Lottery.Bet.CurrentPlay.Option) {
        Site.Lottery.Bet.UI.BackMoneyToWinMoney.find("#play_bet_backToWin_ratio").text("--");
        Site.Lottery.Bet.UI.BackMoneyToWinMoney.find("#play_bet_backToWin_ratioTo").text("--");
        Site.Lottery.Bet.UI.BackMoneyToWinMoney.find("#play_bet_backToWin_win").text("--");

        slider.slider("disable");
    } else {
        Site.Lottery.Bet.UI.BackMoneyToWinMoney.find("#play_bet_backToWin_ratio").text(Site.Lottery.Bet.CurrentPlay.Option.BackMoneyRatio + "%");
        Site.Lottery.Bet.UI.BackMoneyToWinMoney.find("#play_bet_backToWin_ratioTo").text("0%");
        Site.Lottery.Bet.UI.BackMoneyToWinMoney.find("#play_bet_backToWin_win").text("￥" + Site.Lottery.Bet.CurrentPlay.Option.WinMoney);

        slider.slider("option", "max", Site.Lottery.Bet.CurrentPlay.Option.MaxBackMoneyToWinMoney);

        slider.slider(Site.Lottery.Bet.CurrentPlay.Option.MaxBackMoneyToWinMoney > 0 ? "enable" : "disable");
    }

};
///	<summary>
///	反点加奖 返点调整
///	</summary>
Site.Lottery.Func.__BackMoneyToWinMoney_change = function (val) {

    var ratio = Site.Lottery.Bet.CurrentPlay.Option.BackMoneyRatio.sub(val);
    var addWin = val.mul(Site.Lottery.Bet.CurrentPlay.Option.BackMoneyToWinMoneyRatio);
    var win = Site.Lottery.Bet.CurrentPlay.Option.WinMoney.add(addWin);
    
    Site.Lottery.Bet.UI.BackMoneyToWinMoney.find("#play_bet_backToWin_ratio").text(ratio + "%");
    Site.Lottery.Bet.UI.BackMoneyToWinMoney.find("#play_bet_backToWin_ratioTo").text(val + "%");
    Site.Lottery.Bet.UI.BackMoneyToWinMoney.find("#play_bet_backToWin_win").text("￥" + win);
};

///	<summary>
///	初始化启动
///	</summary>
Site.Lottery.Play.prototype.InitAndStart = function () {
    var play = this;

    this.IsChase = this.UI.ChaseCbo.is(":checked");

    play.GetWinMoney();

    //方案
    this.UI.Schemes.find(".title #BetListDelete").click(function () {
        Site.Lottery.Func.__Schemes_title_delall_click.call(this);
    });
    this.UI.Schemes.find(".item #c6").click(function () {
        Site.Lottery.Func.__Schemes_item_del_click.call(this);
        Site.Lottery.Func.__Schemes_Refresh_No();
    });

    //返点加奖
    if (Site.Lottery.BackMoneyToWinMoneyEnable) {
        this.UI.BackMoneyToWinMoney.show();

        var slider = this.UI.BackMoneyToWinMoney.find("#play_bet_backToWin_slider");
        slider.slider({
            step: Site.Lottery.BackMoneyToWinMoneyStep,
            range: "min",
            slide: function (event, ui) {
                return Site.Lottery.Func.__BackMoneyToWinMoney_change(ui.value);
            },
            change: function (event, ui) {
                return Site.Lottery.Func.__BackMoneyToWinMoney_change(ui.value);
            }
        });

        this.UI.BackMoneyToWinMoney.find("#play_bet_backToWin_sub").button().click(function() {
            var val = slider.slider("value") - Site.Lottery.BackMoneyToWinMoneyStep;
            slider.slider("value", val);
        }).find(".ui-button-text").css({
            "height": "15px",
            "width": "15px",
            "padding": "0px",
            "line-height": "15px"
        });
        this.UI.BackMoneyToWinMoney.find("#play_bet_backToWin_add").button().click(function () {
            var val = slider.slider("value") + Site.Lottery.BackMoneyToWinMoneyStep;
            slider.slider("value", val);
        }).find(".ui-button-text").css({
            "height": "15px",
            "width": "15px",
            "padding": "0px",
            "line-height": "15px"
        });
    }
    else {
        this.UI.BackMoneyToWinMoney.hide();
    }

    //单期倍数
    this.UI.SingleMultiply.change(function () {
        Site.Lottery.Func.__Schemes_SingleMultiply_change.call(this);
    }).keypress(Site.Lottery.Func.__Text_CheckInt_keypress)
        .change();

    Site.Lottery.Func.__Schemes_Refresh_No();

    //追号
    this.UI.ChaseCbo.click(function () {
        Site.Lottery.Func.__ChaseCbo_click.call(this);
    });
    this.UI.ChaseCbo.each(function () {
        Site.Lottery.Func.__ChaseCbo_click.call(this);
    });
    this.UI.Chases.find(".title .c1 :checkbox").click(function () {
        Site.Lottery.Func.__Chases_title_chkall_click.call(this);
        Site.Lottery.Func.__Chase_Refresh_No();
    });
    this.UI.Chases.find(".title .c3 :text").change(function () {
        Site.Lottery.Func.__Chases_title_multiply_change.call(this);
        Site.Lottery.Func.__Chase_Refresh_No();
    }).keypress(function (e) {
        var rs = Site.Lottery.Func.__Text_CheckInt_keypress.call(this, e);
        return rs;
    });
    this.UI.Chases.find('.head #issue_count').change(function () {
        Site.Lottery.Func.__Chases_title_chases_change.call(this);
    }).keypress(Site.Lottery.Func.__Text_CheckInt_keypress);
    this.UI.Chases.find('.head #start_issue').change(function () {
        Site.Lottery.Func.__Chases_title_startissue_change(this);
    });
    this.UI.Chases.find("li:not(.title):not(.head)").each(function () {
        var item = $(this);
        item.find(".c1 :checkbox").click(function () {
            Site.Lottery.Func.__Chases_item_chk_click.call(this);
            $(this).parent().parent().find('.c3 :text').change();
        });

        item.find(".c3 :text").change(function () {
            Site.Lottery.Func.__Chases_item_multiply_change.call(this);
            Site.Lottery.Func.__Chase_Refresh_No();
        }).keypress(Site.Lottery.Func.__Text_CheckInt_keypress);
    });
    this.UI.Chases.find("#chase_tool_no").change(function () {
        if (this.checked) {
            play.UI.Chases.find('.head #issue_count').unbind('change');
            play.UI.Chases.find('.head  #start_issue').unbind('change');
            play.UI.Chases.find('.tool').show();
        } else {
            play.UI.Chases.find('.head #issue_count').change(function () {
                Site.Lottery.Func.__Chases_title_chases_change.call(this);
            });
            play.UI.Chases.find('.head #start_issue').change(function () {
                Site.Lottery.Func.__Chases_title_startissue_change(this);
            });
            play.UI.Chases.find('.tool').hide();
        }
    }).change();
    this.UI.Chases.find('.tool #tool_build').click(Site.Lottery.Func.__GetPlayItem);
    this.UI.Chases.find('.tool :radio').click(function () {
        play.UI.Chases.find('.tool .active').removeClass('active').find(':text').attr({ disabled: true });
        $(this).parent().parent().addClass("active").find(':text').attr({ disabled: false });
    });
    this.UI.Chases.find('.tool :text').keypress(function (e) {
        var rs = Site.Lottery.Func.__Text_CheckInt_keypress.call(this, e);
        return rs;
    });
    //this.GetCurrentIssue();
    this.GetChaseIssues();
    //this.GetLastIssue();
    //this.GetHistoryOpenCode();
};




/*************************************************************************************************************************************************************
**  刷新期号
**************************************************************************************************************************************************************/


Site.Lottery.Play.prototype.FirstLoadWin = true;

/// <summary>
/// 获取上一期开奖号码
/// <summary>
Site.Lottery.Play.prototype.GetLastIssue = function() {

    if (Site.Lottery.Bet.LastIssue != null)
        return;

    if (Site.Lottery.Bet.CurrentIssue != null) {
        var d1 = new Date();
        var tmp = (d1 - Site.Lottery.Bet.CurrentIssue.StartTime) - (Site.Lottery.Bet.CurrentIssue.NowTime - Site.Lottery.Bet.CurrentIssue.LoadTime);
        tmp /= 1000;
        var span = tmp - Site.Lottery.Bet.CurrentLottery.OpenWinDelay;
        if (span <= 0) {
            window.setTimeout(Site.Lottery.Bet.GetLastIssue, 5000);
            return;
        }
    }

    Site.getJSON(Site.ServerPath + "Play/LastWinNumber/" + Site.Lottery.Bet.CurrentLottery.ID, null, function(jsondata) {
        try {
            if (jsondata == null)
                return;

            if (jsondata.State == Site.IssueState.Normal)
                return;

            Site.Lottery.Bet.LastIssue =
                {
                    ID: jsondata.ID,
                    Number: jsondata.Number,
                    WinNumber: jsondata.OpenCode,
                    State: jsondata.State
                };

            Site.Lottery.Bet.FirstLoadWin = false;
            Site.Lottery.Bet.UpdateIssueWin();

        } catch(e) {
            if (Site.IsDebug)
                alert(e);
        }
    });
    window.setTimeout(Site.Lottery.Bet.GetLastIssue, 5000);
};
/// <summary>
/// 获取当前彩种的奖金/返点
/// <summary>
Site.Lottery.Play.prototype.GetWinMoney = function () {
    if (Site.Lottery.Bet.WinMoneyList != null)
        return;

    var url = Site.ServerPath + "Play/WinMoneyList/" + Site.Lottery.Bet.CurrentLottery.ID + "?_t=" + Math.random();
    
    $.ajax({
        type: "GET",
        cache: false,
        async: false,
        url: url,
        success: function (jsondata) {
            if (jsondata == null)
                return;
            Site.Lottery.Bet.WinMoneyList = jsondata;
        },
        dataType: 'json'
    });
};

/// <summary>
/// 获取当前彩种的指定玩法的奖金/返点
/// <summary>
Site.Lottery.Play.prototype.GetPlayTypeWinMoney = function (fun) {
    var rs = null;
    if (Site.Lottery.Bet.WinMoneyList) {
        $.each(Site.Lottery.Bet.WinMoneyList, function (i, p) {
            if (fun(p)) {
                rs = p;
                return false;
            }
        });
    }
    return rs;
};
/// <summary>
/// 获取追号期号
/// <summary>
Site.Lottery.Play.prototype.GetChaseIssues = function() {

    if (Site.Lottery.Bet.ChaseIssues != null)
        return;
    Site.getJSON(Site.ServerPath + "Play/ChaseIssue/" + Site.Lottery.Bet.CurrentLottery.ID, null, function(jsondata, args) {
        try {
            if (jsondata == null)
                return;


            Site.Lottery.Bet.ChaseIssues = [];
            if (jsondata.Error) {
                return;
            }

            if ($.isArray(jsondata)) {
                var select = Site.Lottery.Bet.UI.Chases.find('.head #start_issue');
                select.find('option').each(function() {
                    this.parentNode.removeChild(this);
                });
                $.each(jsondata, function(i, item) {
                    item.StartTime = eval('new ' + item.StartTime.substring(1, item.StartTime.length - 1));
                    item.EndTime = eval('new ' + item.EndTime.substring(1, item.EndTime.length - 1));
                    Site.Lottery.Bet.ChaseIssues.push(item);
                    var html = '<option value="' + item.ID + '">[' + (i + 1) + ']&nbsp;' + item.Number + '</option>';
                    $(html).appendTo(select);
                });
                Site.Lottery.Func.__Chases_title_startissue_set();
            }
            Site.Lottery.Bet.UI.Chases.find('.head #issue_sumcount').html('(最多' + Site.Lottery.Bet.ChaseIssues.length + '期)');

        } catch(e) {
            if (Site.IsDebug)
                alert(e);
        }
    });

    window.setTimeout(Site.Lottery.Bet.GetChaseIssues, 5000);
};

/// <summary>
/// 更新开奖号码
/// <summary>
Site.Lottery.Play.prototype.UpdateIssueWin = function() {


    if (Site.Lottery.Bet.LastIssue == null)
        return;

    var nums = [];
    if (Site.Lottery.Bet.LastIssue.WinNumber.indexOf(",") >= 0)
        nums = Site.Lottery.Bet.LastIssue.WinNumber.split(',');
    else if (Site.Lottery.Bet.LastIssue.WinNumber.indexOf(" ") >= 0)
        nums = Site.Lottery.Bet.LastIssue.WinNumber.split(' ');
    else
        nums = Site.Lottery.Bet.LastIssue.WinNumber.split('');
    Site.Lottery.Bet.UI.LastWin.html('');
    for (var n in nums) {
        Site.Lottery.Bet.UI.LastWin.append('<span class="play_head_lastwin_item">' + nums[n] + '</span>');
    }
    if (Site.Lottery.Bet.UI.OpenCodeHistory.find("td:contains(" + Site.Lottery.Bet.LastIssue.Number + ")").length)
        return;
    Site.Lottery.Bet.GetHistoryOpenCode();
};

Site.Lottery.Play.prototype.GetHistoryOpenCode = function() {

    Site.Lottery.Bet.UI.OpenCodeHistory.load(Site.ServerPath + "Play/OpenCodeHistory/" + Site.Lottery.Bet.CurrentLottery.ID + "?+rount=" + Math.random(), null, function() {

        if (this.length && this.is("#tb_opencode_history"))
            return true;
        else
            return false;
    });
};



///	<summary>
///	取得当前种彩正在进行的期号
///	</summary>
Site.Lottery.Play.prototype.GetCurrentIssue = function() {
    if (Site.Lottery.Bet.CurrentIssue != null)
        return;
    Site.getJSON(Site.ServerPath + "Play/CurrentIssue/" + Site.Lottery.Bet.CurrentLottery.ID, null, function(jsondata) {
        try {
            if (jsondata == null) {
                Site.Lottery.Bet.LockCountDown();
                return;
            }

            Site.Lottery.Bet.CurrentIssue = { };
            Site.Lottery.Bet.CurrentIssue.IssueID = jsondata.ID;
            Site.Lottery.Bet.CurrentIssue.IssueName = jsondata.Number;
            Site.Lottery.Bet.CurrentIssue.StartTime = new Date(jsondata.StartTime);
            Site.Lottery.Bet.CurrentIssue.EndTime = new Date(jsondata.EndTime);
            Site.Lottery.Bet.CurrentIssue.NowTime = new Date(jsondata.NowTime);
            Site.Lottery.Bet.NextStart = new Date(jsondata.NextStart);
            Site.Lottery.Bet.CurrentIssue.LoadTime = new Date();

            Site.Lottery.Bet.UI.IssueName.html("第<font color='red'>" + jsondata.Number + "</font>期");
            Site.Lottery.Bet.UI.IssueID.val(jsondata.ID);
            Site.Lottery.Bet.UI.IssueID.valid();

            //开始倒计时
            if (!Site.Lottery.Bet.IsTimeStart) {
                //Site.Lottery.Bet.UI.SubmitBtn.removeAttr("disabled");
                //Site.Lottery.Bet.UI.SubmitBtn.removeClass("locked");
                Site.Lottery.Bet.IsTimeStart = true;
                Site.Lottery.Bet.CountDownTime();

            }
            Site.Lottery.Bet.CanBet = true;
        } catch(e) {
            if (Site.IsDebug) alert("Site.Issue.GetCurrentIssue():" + e);
        }
    });

    window.setTimeout(Site.Lottery.Bet.GetCurrentIssue, 5000);
};

///	<summary>
///	本期投注已截止
///	</summary>
Site.Lottery.Play.prototype.LockCountDown = function() {
    Site.Lottery.Bet.IsTimeStart = false;
    Site.Lottery.Bet.UI.IssueName.html('期号:等待下一期...');
    //Site.Lottery.Bet.UI.SubmitBtn.attr("disabled",'true');
    //Site.Lottery.Bet.UI.SubmitBtn.addClass("locked");
    if (!Site.Lottery.Bet.IsChase) {
        Site.Lottery.Bet.UI.IssueID.val('');
        Site.Lottery.Bet.UI.IssueID.valid();
    }

};

///	<summary>
///	本期投注倒计时
///	</summary>
Site.Lottery.Play.prototype.CountDownTime = function() {
    try {
        if (Site.Lottery.Bet.CurrentIssue == null)
            return;
        if (Site.Lottery.Bet.IsTimeStart == false)
            return;
        var d1 = new Date();

        var tmp = (Site.Lottery.Bet.CurrentIssue.EndTime - Site.Lottery.Bet.CurrentIssue.NowTime) - (d1 - Site.Lottery.Bet.CurrentIssue.LoadTime);

        if (tmp <= 0) { //倒计时结束

            Site.Lottery.Bet.LockCountDown();

            Site.Lottery.Bet.ChaseIssues = null; //加载追号期号
            Site.Lottery.Bet.GetChaseIssues();

            Site.Lottery.Bet.WaitNextIssue();
            return;
        }

        window.setTimeout(Site.Lottery.Bet.CountDownTime, 1000); //间隔一秒种
        var span = new Date("1-1-1990");
        span.setSeconds(tmp / 1000);
        var timestr = "离本期截止：";
        var isred = false;
        var hours = span.getHours();
        var minute = span.getMinutes();
        var second = span.getSeconds();
        var date = span.getDate() - 1;


        hours += date * 24;

        if (hours >= 10)
            timestr += hours;
        else if (hours > 0)
            timestr += "0" + hours;
        else
            timestr += "00";
        timestr += ":";

        if (minute >= 10)
            timestr += minute;
        else if (minute > 0)
            timestr += "0" + minute;
        else
            timestr += "00";
        timestr += ":";

        if (second >= 10)
            timestr += second;
        else if (second > 0)
            timestr += "0" + second;
        else
            timestr += "00";

        Site.Lottery.Bet.UI.ContDown.html(timestr);


    } catch(e) {
        if (Site.IsDebug)
            alert("Site.Littery.Play.CountDown():" + e);
    }
};


///	<summary>
///	等待下一期的开始
///	</summary>
Site.Lottery.Play.prototype.WaitNextIssue = function() {
    try {
        if (Site.Lottery.Bet.CurrentIssue == null)
            return;
        var d1 = new Date();
        var tmp = (Site.Lottery.Bet.NextStart - Site.Lottery.Bet.CurrentIssue.NowTime) - (d1 - Site.Lottery.Bet.CurrentIssue.LoadTime);
        if (tmp <= 0) { //倒计时结束

            Site.Lottery.Bet.UI.LastWin.html('载入中...');

            Site.Lottery.Bet.CurrentIssue = null; //加载一期
            Site.Lottery.Bet.GetCurrentIssue();

            Site.Lottery.Bet.LastIssue = null; //加载这期的开奖号码
            Site.Lottery.Bet.GetLastIssue();
            return;
        }
        Site.Lottery.Bet.CanBet = false;

        window.setTimeout(Site.Lottery.Bet.WaitNextIssue, 1000); //间隔一秒种
        var span = new Date("1-1-1990");
        span.setSeconds(tmp / 1000);
        var timestr = "离下期开始：";
        var hours = span.getHours();
        var minute = span.getMinutes();
        var second = span.getSeconds();
        var date = span.getDate() - 1;

        hours += date * 24;

        if (hours >= 10)
            timestr += hours;
        else if (hours > 0)
            timestr += "0" + hours;
        else
            timestr += "00";
        timestr += ":";

        if (minute >= 10)
            timestr += minute;
        else if (minute > 0)
            timestr += "0" + minute;
        else
            timestr += "00";
        timestr += ":";

        if (second >= 10)
            timestr += second;
        else if (second > 0)
            timestr += "0" + second;
        else
            timestr += "00";

        Site.Lottery.Bet.UI.ContDown.html(timestr);

    } catch(e) {
        if (Site.IsDebug)
            alert("Site.Lottery.Play.WaitNextIssue():" + e);
    }
};


/*************************************************************************************************************************************************************
**  开奖视频
**************************************************************************************************************************************************************/

Site.Lottery.CurrentLottery = { ID: null, Name: null, OpenCodeLength: null };

///	<summary>
///	跟据 ID 获取元素
///	</summary>
Site.i$ = function (o) { if (typeof (o) == "object") { return o; } else { return document.getElementById(o); } }
///	<summary>
///	跟据 TagName 获取元素
///	</summary>
Site.t$ = function (o) { if (typeof (o) == "object") { return o; } else { return document.getElementsByTagName(o); } }
///	<summary>
///	跟据 Name 获取元素集合
///	</summary>
Site.n$ = function (o) { if (typeof (o) == "object") { return o; } else { return document.getElementsByName(o); } }

///	<summary>
///	期号相关
///	</summary>
Site.Issue = {};

///	<summary>
///	当前期的内容
///	</summary>
Site.Issue.IssueState = { Normal: 0, Opend: 1 };

///	<summary>
///	当前期的内容
///	</summary>
Site.Issue.CurrentIssue = null;

///	<summary>
///	上一期的内容
///	</summary>
Site.Issue.LastIssue = null;

Site.Issue.LastIssueID = null;

///	<summary>
///	是否正在进行倒计时
///	</summary>
Site.Issue.IsTimeStart = false;

///	<summary>
///	指示是否播放声音
///	</summary>
Site.Issue.IsPlaySound = true;

///	<summary>
///	播放声音的列表
///	</summary>
Site.Issue.Sounds = [{ Check: function (span) {
    var hours = span.getHours();
    var minute = span.getMinutes();
    var second = span.getSeconds();
    var date = span.getDate();
    if (!Site.Issue.IsPlaySound)
        this.Stop();
    return Site.Issue.IsPlaySound && !playsound && date == 1 && hours == 0 && minute == 0 && second==20;
}, Play: function () {
    if (!Site.Issue.IsPlaySound)
        this.Stop();
    if (playsound)
        return;
    $("#divplaySound").load(Site.ServerPath + "Content/Sound.htm");
    playsound = true;
},
    Stop: function () { $("#divplaySound").html(""); }
}];

///	<summary>
///	获取上一期的开奖号码
///	</summary>
Site.Issue.GetLastIssue = function() {
    if (Site.Issue.LastIssue != null)
        return;
    Site.getJSON(Site.ServerPath + "Play/LastWinNumber/" + Site.Lottery.CurrentLottery.ID, null, function(jsondata) {
        try {
            if (jsondata == null)
                return;

            $("#lastIssueName")[0].innerHTML = "第" + jsondata.Number + "期";
            $("#waittimespan span")[0].innerHTML = "第" + jsondata.Number + "期正在开奖...";

            if (Site.Issue.WaitNumList == null) {
                Site.i$("tbwinnostate").style.display = "none";
                Site.i$("waittimespan").style.display = "block";
                var len = 5 - Site.Lottery.CurrentLottery.OpenCodeLength;
                var winnums = $("#openwinnumber span");
                var tmp = winnums.splice(0, len);
                $.each(tmp, function(i, n) {
                    n.innerText = " ";
                });
                Site.Issue.WaitNumList = winnums; //开始滚动数字
                Site.Issue.WaitNextWinNumber();
            }

            if (jsondata.State == Site.Issue.IssueState.Normal)
                return;

            Site.Issue.LastIssue = { };
            Site.Issue.LastIssue.IssueID = jsondata.ID;
            Site.Issue.LastIssue.IssueName = jsondata.Number;
            Site.Issue.LastIssue.WinNumber = jsondata.OpenCode;
            Site.Issue.LastIssue.State = jsondata.State;

            Site.Issue.UpdateIssueWin();

        } catch(e) {
            if (Site.IsDebug)
                alert(e);
        }
    });

    window.setTimeout(Site.Issue.GetLastIssue, 5000);
};

Site.Issue.setKjXiTai = function (s) {
    var a = s.split("");
    Site.i$("xt_3x").innerHTML = "";
    Site.i$("xt_2xh").innerHTML = "";
    Site.i$("xt_3xh").innerHTML = "";
    Site.i$("xt_dxds").innerHTML = "";

    if (Site.Lottery.CurrentLottery.ID == 9) {
        $("#waittimespan").show();
        $("#tbwinnostate").hide();
        $("#waittimespan .waitnexttxt").text(s);
    } else if (Site.Lottery.CurrentLottery.OpenCodeLength == 3) {
        if (a[1] == a[2] || a[1] == a[3] || a[2] == a[3])
            Site.i$("xt_3x").innerHTML = "组三";
        else
            Site.i$("xt_3x").innerHTML = "组六";
    } else if (Site.Lottery.CurrentLottery.OpenCodeLength == 5) {

        //三星
        var z = "";
        if (a[2] == a[3] || a[2] == a[4] || a[3] == a[4]) {
            z = "组三";
        } else {
            z = "组六";
        }
        Site.i$("xt_3x").innerHTML = z;
        //二星和
        Site.i$("xt_2xh").innerHTML = a[3] * 1 + a[4] * 1;
        // 三星和
        Site.i$("xt_3xh").innerHTML = a[3] * 1 + a[4] * 1 + a[2] * 1;
        var aa, b, c, d;
        if (a[3] * 1 < 6) { aa = "小"; } else { aa = "大"; }
        if (a[3] * 1 % 2 == 0) { b = "双"; } else { b = "单"; }
        if (a[4] * 1 < 6) { c = "小"; } else { c = "大"; }
        if (a[4] * 1 % 2 == 0) { d = "双"; } else { d = "单"; }
        Site.i$("xt_dxds").innerHTML = aa + c + "&nbsp;" + aa + d + "&nbsp;" + b + c + "&nbsp;" + b + d;
    }
};


/// <sumary>
/// 更新开奖号码
/// </sumary>
Site.Issue.UpdateIssueWin = function() {
    if (Site.Issue.LastIssue == null)
        return;

    Site.Issue.UpdateWinNumber();
    Site.Lottery.Bet.GetHistoryOpenCode();
};

var tempwinnumber = 0;
Site.Issue.UpdateWinNumber = function() {
    Site.Issue.WaitNumList = [];
    var tmparray = [];
    var len = 5 - Site.Lottery.CurrentLottery.OpenCodeLength;
    var winnums = $("#openwinnumber span");
    var tmp = winnums.splice(0, len);
    $.each(tmp, function(i, n) {
        n.innerText = " ";
    });
    var nums = [];
    if (Site.Lottery.CurrentLottery.ID == 9)
        nums = Site.Issue.LastIssue.WinNumber.replace(/,/g, "").split('');
    else if (Site.Issue.LastIssue.WinNumber.indexOf(",") >= 0)
        nums = Site.Issue.LastIssue.WinNumber.split(',');
    else if (Site.Issue.LastIssue.WinNumber.indexOf(" ") >= 0)
        nums = Site.Issue.LastIssue.WinNumber.split(' ');
    else
        nums = Site.Issue.LastIssue.WinNumber.split('');

    $.each(winnums, function(i, n) {
        if (i > tempwinnumber) {
            tmparray.push(n);
        } else {
            n.innerText = nums[i];
        }
    });
    if (tmparray.length == 0) {
        Site.i$("tbwinnostate").style.display = "block";
        Site.i$("waittimespan").style.display = "none";
        Site.Issue.setKjXiTai(Site.Issue.LastIssue.WinNumber);
        Site.Issue.WaitNumList = null;
        tempwinnumber = 0;
        var dd = $("#divoldissue");
        if (dd.length > 0)
            dd.load(Site.ServerPath + "Issues/HistoryLeft/" + Site.Lottery.CurrentLottery.ID + "?tp=" + new Date() / 1000);
        return;
    }
    tempwinnumber++;
    Site.Issue.WaitNumList = tmparray;
    window.setTimeout(Site.Issue.UpdateWinNumber, 1000);
};




Site.Issue.WaitNumList = null;

var tempnum = 0;
/// <sumary>
/// 等待下一期开奖
/// </sumary>
Site.Issue.WaitNextWinNumber = function() {
    if (Site.Issue.WaitNumList == null)
        return;
    $.each(Site.Issue.WaitNumList, function(i, n) {
        n.innerText = tempnum;
    });
    tempnum++;
    if (tempnum >= 10)
        tempnum = 0;
    window.setTimeout(Site.Issue.WaitNextWinNumber, 70);
};

///	<summary>
///	取得当前种彩正在进行的期号
///	</summary>
Site.Issue.GetCurrentIssue = function() {
    if (Site.Issue.CurrentIssue != null)
        return;
    Site.getJSON(Site.ServerPath + "Play/CurrentIssue/" + Site.Lottery.CurrentLottery.ID, null, function(jsondata) {
        try {
            if (jsondata == null) {
                Site.Issue.LockCountDown();
                return;
            }

            Site.Lottery.Bet.CurrentIssue = { };
            Site.Lottery.Bet.CurrentIssue.IssueID = jsondata.ID;
            Site.Lottery.Bet.CurrentIssue.IssueName = jsondata.Number;
            Site.Lottery.Bet.CurrentIssue.StartTime = new Date(jsondata.StartTime);
            Site.Lottery.Bet.CurrentIssue.EndTime = new Date(jsondata.EndTime);
            Site.Lottery.Bet.CurrentIssue.NowTime = new Date(jsondata.NowTime);
            Site.Lottery.Bet.NextStart = new Date(jsondata.NextStart);
            Site.Lottery.Bet.CurrentIssue.LoadTime = new Date();

            Site.Issue.CurrentIssue = { };
            Site.Issue.CurrentIssue.IssueID = jsondata.ID;
            Site.Issue.CurrentIssue.IssueName = jsondata.Number;
            Site.Issue.CurrentIssue.StartTime = new Date(jsondata.StartTime);
            Site.Issue.CurrentIssue.EndTime = new Date(jsondata.EndTime);
            Site.Issue.CurrentIssue.NowTime = new Date(jsondata.NowTime);
            Site.Issue.NextStart = new Date(jsondata.NextStart);
            Site.Issue.CurrentIssue.LoadTime = new Date();

            Site.Lottery.Bet.CanBet = true;
            Site.Lottery.Bet.UI.IssueID.val(jsondata.ID);
            Site.Lottery.Bet.UI.IssueID.valid();

            $("#currentIssueName").each(function(i) {
                this.innerHTML = "第" + jsondata.Number + "期 剩余投注时间";
            });
            //开始倒计时
            if (!Site.Issue.IsTimeStart) {
                Site.Issue.IsTimeStart = true;
                $(".vediotime span").css("display", "block");
                $(".vediotime img").css("display", "none");
                Site.Issue.CountDownTime();
            }
        } catch(e) {
            if (Site.IsDebug) alert("Site.Issue.GetCurrentIssue():" + e);
        }
    });

    window.setTimeout(Site.Issue.GetCurrentIssue, 5000);
};

///	<summary>
///	本期投注已截止
///	</summary>
Site.Issue.LockCountDown = function() {
    Site.Issue.IsTimeStart = false;
    $(".vediotime span").css("display", "none");
    $(".vediotime img").css("display", "block");
    Site.Lottery.Bet.UI.IssueName.html('期号:等待下一期...');
    //Site.Lottery.Bet.UI.SubmitBtn.attr("disabled",'true');
    //Site.Lottery.Bet.UI.SubmitBtn.addClass("locked");
    if (!Site.Lottery.Bet.IsChase) {
        Site.Lottery.Bet.UI.IssueID.val('');
        Site.Lottery.Bet.UI.IssueID.valid();
    }
};

///	<summary>
///	本期投注倒计时
///	</summary>
Site.Issue.CountDownTime = function() {
    try {
        if (Site.Issue.CurrentIssue == null)
            return;
        if (Site.Issue.IsTimeStart == false)
            return;
        var d1 = new Date();
        var tmp = (Site.Issue.CurrentIssue.EndTime - Site.Issue.CurrentIssue.NowTime) - (d1 - Site.Issue.CurrentIssue.LoadTime);

        if (tmp <= 0) { //倒计时结束
            playsound = false;
            $.each(Site.Issue.Sounds, function(i, n) { //停止播发声音
                n.Stop();
            });
            Site.Issue.LockCountDown();
            Site.Issue.WaitNextIssue();

            Site.Lottery.Bet.ChaseIssues = null; //加载追号期号
            Site.Lottery.Bet.GetChaseIssues();
            return;
        }

        window.setTimeout(Site.Issue.CountDownTime, 1000); //间隔一秒种
        var span = new Date("1-1-1990");
        span.setSeconds(tmp / 1000);
        var timestr = "";
        var isred = false;
        var hours = span.getHours();
        var minute = span.getMinutes();
        var second = span.getSeconds();
        var date = span.getDate();

        $.each(Site.Issue.Sounds, function(i, n) {
            if (n.Check(span))
                n.Play();
        });

        if (hours > 0 || date > 1) { //间隔超过1小时
            if (hours < 10)
                timestr += "0" + hours + ":";
            else
                timestr += hours + ":";
            if (minute < 10)
                timestr += "0" + minute;
            else
                timestr += minute;
            timestr += "<br /><font style='font-size:18px'>";
            if (second < 10)
                timestr += "0" + second;
            else
                timestr += second;
            timestr += " s</font>";
        } else if (minute == 0) { //间隔不足1分钟
            timestr = "00:";
            if (second < 10)
                timestr += "0" + second;
            else
                timestr += second;
            isred = true;
        } else { //间隔在小时时以内
            if (minute < 10)
                timestr += "0" + minute + ":";
            else
                timestr += minute + ":";
            if (second < 10)
                timestr += "0" + second;
            else
                timestr += second;
        }

        $(".vediotime span").each(function(item) {
            this.innerHTML = timestr;
            if (isred)
                this.style.color = "Red";
            else
                this.style.color = "Yellow";
        });

    } catch(e) {
        if (Site.IsDebug)
            alert("Site.Issue.CountDown():" + e);
    }
};
var playsound = false;
///	<summary>
///	等待下一期的开始
///	</summary>
Site.Issue.WaitNextIssue = function() {
    try {
        if (Site.Issue.CurrentIssue == null)
            return;
        var d1 = new Date();
        var tmp = (Site.Issue.NextStart - Site.Issue.CurrentIssue.EndTime) - (d1 - Site.Issue.CurrentIssue.LoadTime);
        if (tmp <= 0) { //倒计时结束

            $("#currentIssueName").each(function(i) {
                this.innerHTML = "载入中...";
            });
            Site.Issue.CurrentIssue = null; //加载一期
            Site.Issue.GetCurrentIssue();
            Site.Issue.LastIssue = null; //加载这期的开奖号码

            Site.i$("tbwinnostate").style.display = "none";
            Site.i$("waittimespan").style.display = "block";

            if (Site.Issue.WaitNumList == null) {
                var len = 5 - Site.Lottery.CurrentLottery.OpenCodeLength;
                var winnums = $("#openwinnumber span");
                var tmp = winnums.splice(0, len);
                $.each(tmp, function(i, n) {
                    n.innerText = " ";
                });
                Site.Issue.WaitNumList = winnums; //开始滚动数字
                Site.Issue.WaitNextWinNumber();
            }
            Site.Issue.GetLastIssue();
            return;
        }

        Site.Lottery.Bet.CanBet = false;

        window.setTimeout(Site.Issue.WaitNextIssue, 1000); //间隔一秒种
        var span = new Date("1-1-1990");
        span.setSeconds(tmp / 1000);
        var timestr = "";
        var hours = span.getHours();
        var minute = span.getMinutes();
        var second = span.getSeconds();
        var date = span.getDate();
        var strmsg = "本期投注已经截止距离下期：";

        if (hours > 0 || date > 1) { //间隔超过1小时
            if (hours < 10)
                timestr += "0" + hours + ":";
            else
                timestr += hours + ":";
            if (minute < 10)
                timestr += "0" + minute + ":";
            else
                timestr += minute + ":";
            if (second < 10)
                timestr += "0" + second;
            else
                timestr += second;
            strmsg = "本期投注已经截止下期：";
        } else if (minute == 0) { //间隔不足1分钟
            timestr = "00:";
            if (second < 10)
                timestr += "0" + second;
            else
                timestr += second;
        } else { //间隔在小时时以内
            if (minute < 10)
                timestr += "0" + minute + ":";
            else
                timestr += minute + ":";
            if (second < 10)
                timestr += "0" + second;
            else
                timestr += second;
        }
        $("#currentIssueName").each(function(i) {
            this.innerHTML = strmsg + timestr;
        });
    } catch(e) {
        if (Site.IsDebug)
            alert("Site.Issue.WaitNextIssue():" + e);
    }
};




/*************************************************************************************************************************************************************
**  投注面板
**************************************************************************************************************************************************************/


Site.Lottery.Func.GetInputPanel = function(names, min, max, flag) {

    var nums = "";
    for (var i = min, j = 1; i < max + 1; i++, j++) {
        nums += "<li class='number'>" + i + "</li>";
        if (max - min > 15 && j == (max - min + 1) / 2) {
            nums += "</ul><ul class='ul_number'><li class='empty_li'></li>";
        }
    }
    if (flag) {
        nums += "<li class='tool li'>清</li><li class='tool li'>偶</li><li class='tool li'>奇</li><li class='tool li'>小</li><li class='tool li'>大</li><li class='tool li'>全</li>";
    }
    var txt = "";
    for (var i = 0; i < names.length; i++) {
        if (names[i] == "" || names[i] == null)
            continue;
        txt += "<ul class='ul_number'><li class='head'>" + names[i] + "</li>" + nums + "</ul>";
    }
    return txt;
};

Site.Lottery.PlayTypes = {};
Site.Lottery.IsSSL = false;
////////////////直选////////////////
Site.Lottery.PlayTypes.ZhiXuan = function (name1, name2, name3) {
    this.PlayTypeName = '';
    this.PlayTypeID = -1;
    this.Names = [name1, name2, name3];
    this.Min = 0;
    this.Max = 9;
    this.HasInputModel = true; //是否具有手动输入的功能
    this.Flag = true; //是否有筛选器
    this.InputNums = []; //手工输入的号码
    this.ChoseNums = [];
    for (var i = 0; i < this.Names.length; i++) {
        this.ChoseNums[this.Names[i]] = '';
    }
    this.AddChoseNums = function (id, number) {
        this.ChoseNums[id] += number;
    };
    this.RemoveChoseNums = function (id, number) {
        this.ChoseNums[id] = this.ChoseNums[id].replace(number, '');
    };
    this.GetNumsCount = function() { //获取购买号码的注数
        if (this.InputNums.length != 0)
            return this.InputNums.length;
        var count = 0;
        for (var i = 0; i < this.Names.length; i++) {
            var value = this.ChoseNums[this.Names[i]];
            if (value == '') {
                return 0;
            }
            value = value.replace(/ /g, '');
            if (i == 0) {
                count = value.length;
            } else {

                count *= value.length;
            }
        }
        return count;
    };
};
////////////////组三////////////////
Site.Lottery.PlayTypes.ZuSan = function () {
    this.PlayTypeName = '';
    this.PlayTypeID = -1;
    this.Names = ["组三"];
    this.Min = 0;
    this.Max = 9;
    this.HasInputModel = true; //是否具有手动输入的功能
    this.Flag = true; //是否有筛选器
    this.InputNums = []; //手工输入的号码
    this.ChoseNums = [];
    this.ChoseNums["组三"] = "";
    this.AddChoseNums = function (id, number) {
        this.ChoseNums[id] += number;
    };
    this.RemoveChoseNums = function (id, number) {
        this.ChoseNums[id] = this.ChoseNums[id].replace(number, '');
    };
    this.GetNumsCount = function() { //获取购买号码的注数
        var value = this.ChoseNums[this.Names[0]];
        value = value.replace(/ /g, '');
        var l = value.length;
        if (1 < 2)
            return 0;
        else {
            return l * (l - 1);
        }
    };
};
////////////////组六////////////////
Site.Lottery.PlayTypes.ZuLiu = function () {
    this.PlayTypeName = '';
    this.PlayTypeID = -1;
    this.Names = ["组六"];
    this.Min = 0;
    this.Max = 9;
    this.HasInputModel = true; //是否具有手动输入的功能
    this.Flag = true; //是否有筛选器
    this.InputNums = []; //手工输入的号码
    this.ChoseNums = [];
    this.ChoseNums["组六"] = "";
    this.AddChoseNums = function (id, number) {
        this.ChoseNums[id] += number;
    };
    this.RemoveChoseNums = function (id, number) {
        this.ChoseNums[id] = this.ChoseNums[id].replace(number, '');
    };
    this.NumsCount = [0, 0, 0, 1, 4, 10, 20, 35, 56, 84, 120];
    this.GetNumsCount = function() { //获取购买号码的注数
        var value = this.ChoseNums[this.Names[i]];
        if (value == '') {
            return 0;
        }
        value = value.replace(/ /g, '');
        return this.NumsCount[value.length];
    };
};
////////////////值和////////////////
Site.Lottery.PlayTypes.ZhiHe = function (name) {
    this.PlayTypeName = '';
    this.PlayTypeID = -1;
    this.Names = ["直选和值"];
    if (name != null && name != '')
        this.Names = [name];
    this.Min = 0;
    this.Max = 27;
    this.HasInputModel = false; //是否具有手动输入的功能
    this.Flag = false; //是否有筛选器
    this.InputNums = []; //手工输入的号码
    this.ChoseNums = [];
    this.ChoseNums["直选和值"] = "";
    this.ChoseNums[name] = '';
    this.AddChoseNums = function (id, number) {
        if (this.ChoseNums[id].length == 0)
            this.ChoseNums[id] += number;
        else
            this.ChoseNums[id] += "," + number;
    };
    this.RemoveChoseNums = function (id, number) {
        var list = this.ChoseNums[id].split(',');
        this.ChoseNums[id] = '';
        for (var i = 0; i < list.length; i++) {
            if (list[i] == number)
                continue;
            else {
                if (this.ChoseNums[id].length == 0) {
                    this.ChoseNums[id] = list[i];
                } else {
                    this.ChoseNums[id] += ',' + list[i];
                }
            }
        }
    };
    this.NumsCount = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 63, 69, 73, 75, 75, 73, 69, 63, 55, 45, 36, 28, 21, 15, 10, 6, 3, 1];
    this.GetNumsCount = function() { //获取购买号码的注数
        var value = this.ChoseNums[this.Names[0]];
        if (value == '')
            return 0;
        value = value.replace(/ /g, '');
        var count = 0;
        var list = value.split(',');
        for (i = 0; i < list.length; i++) {
            var n = parseInt(list[i]);
            count += this.NumsCount[n];
        }
        return count;
    };
};
////////////////组和////////////////
Site.Lottery.PlayTypes.ZuHe = function (name) {
    this.PlayTypeName = '';
    this.PlayTypeID = -1;
    this.Names = ["组选和值"];
    if (name != null && name != '')
        this.Names = [name];
    this.Min = 1;
    this.Max = 26;
    this.HasInputModel = false; //是否具有手动输入的功能
    this.Flag = false; //是否有筛选器
    this.InputNums = []; //手工输入的号码
    this.ChoseNums = [];
    this.ChoseNums["组选和值"] = "";
    this.ChoseNums[name] = '';
    this.AddChoseNums = function (id, number) {
        if (this.ChoseNums[id].length == 0)
            this.ChoseNums[id] += number;
        else
            this.ChoseNums[id] += "," + number;
    };
    this.RemoveChoseNums = function (id, number) {
        var list = this.ChoseNums[id].split(',');
        this.ChoseNums[id] = '';
        for (var i = 0; i < list.length; i++) {
            if (list[i] == number)
                continue;
            else {
                if (this.ChoseNums[id].length == 0) {
                    this.ChoseNums[id] = list[i];
                } else {
                    this.ChoseNums[id] += ',' + list[i];
                }
            }
        }
    };
    this.NumsCount = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 63, 69, 73, 75, 75, 73, 69, 63, 55, 45, 36, 28, 21, 15, 10, 6, 3, 1];
    this.GetNumsCount = function() { //获取购买号码的注数
        var value = this.ChoseNums[this.Names[0]];
        if (value == '')
            return 0;
        value = value.replace(/ /g, '');
        var count = 0;
        var list = value.split(',');
        for (i = 0; i < list.length; i++) {
            var n = parseInt(list[i]);
            count += this.NumsCount[n];
        }
        return count;
    };
};
////////////////前二////////////////
Site.Lottery.PlayTypes.QianEr = function() {
    this.PlayTypeName = '';
    this.PlayTypeID = -1;
    this.Names = ["", ""];
    this.Min = 0;
    this.Max = 9;
    this.HasInputModel = true; //是否具有手动输入的功能
    this.Flag = true; //是否有筛选器
    this.InputNums = []; //手工输入的号码
    this.ChoseNums = [];
    if (Site.Lottery.IsSSL) {
        this.Names = ["万位", "千位"];
    } else {
        this.Names = ["百位", "十位"];
    }
    this.ChoseNums[this.Names[0]] = "";
    this.ChoseNums[this.Names[1]] = "";
    this.AddChoseNums = function(id, number) {
        this.ChoseNums[id] += number;
    };
    this.RemoveChoseNums = function(id, number) {
        this.ChoseNums[id] = this.ChoseNums[id].replace(number, '');
    };
    this.GetNumsCount = function() { //获取购买号码的注数
        var count = 0;
        for (var i = 0; i < this.Names.length; i++) {
            var value = this.ChoseNums[this.Names[i]];
            if (value == '') {
                return 0;
            }
            value = value.replace(/ /g, '');
            if (i == 0) {
                count = value.length;
            } else {
                count *= value.length;
            }
        }
        return count;
    };
};
////////////////后二////////////////
Site.Lottery.PlayTypes.HouEr = function (name1, name2) {
    this.PlayTypeName = '';
    this.PlayTypeID = -1;
    this.Names = [name1, name2];
    this.Min = 0;
    this.Max = 9;
    this.HasInputModel = true; //是否具有手动输入的功能
    this.Flag = true; //是否有筛选器
    this.InputNums = []; //手工输入的号码
    this.ChoseNums = [];
    this.ChoseNums[name1] = "";
    this.ChoseNums[name2] = "";
    this.AddChoseNums = function (id, number) {
        this.ChoseNums[id] += number;
    };
    this.RemoveChoseNums = function (id, number) {
        this.ChoseNums[id] = this.ChoseNums[id].replace(number, '');
    };
    this.GetNumsCount = function() { //获取购买号码的注数
        var count = 0;
        for (var i = 0; i < this.Names.length; i++) {
            var value = this.ChoseNums[this.Names[i]];
            if (value == '') {
                return 0;
            }
            value = value.replace(/ /g, '');
            if (i == 0) {
                count = value.length;
            } else {
                count *= value.length;
            }
        }
        return count;
    };
};
////////////////定位胆////////////////
Site.Lottery.PlayTypes.DingWeiDan = function () {
    this.PlayTypeName = '';
    this.PlayTypeID = -1;
    this.Names = ["", "", "", "", ""];
    this.Min = 0;
    this.Max = 9;
    this.HasInputModel = false; //是否具有手动输入的功能
    this.Flag = true; //是否有筛选器
    this.InputNums = []; //手工输入的号码
    this.ChoseNums = [];
    if (Site.Lottery.IsSSL) {
        this.Names = ["万位", "千位", "百位", "十位", "个位"];
    }
    else {
        this.Names = ["百位", "十位", "个位"];
    }
    for (var i = 0; i < this.Names.length; i++) {
        if (this.Names[i] == "" || this.Names[i] == null)
            continue;
        this.ChoseNums[this.Names[i]] = '';
    }
    this.AddChoseNums = function (id, number) {
        this.ChoseNums[id] += number;
    };
    this.RemoveChoseNums = function (id, number) {
        this.ChoseNums[id] = this.ChoseNums[id].replace(number, '');
    };
    this.GetNumsCount = function() { //获取购买号码的注数
        var count = 0;
        for (var i = 0; i < this.Names.length; i++) {
            if (this.Names[i] == "" || this.Names[i] == null)
                continue;
            var value = this.ChoseNums[this.Names[i]];
            if (value == '') {
                continue;
            }
            value = value.replace(/ /g, '');
            count += value.length;
        }
        return count;
    };
};
////////////////不定位胆////////////////
Site.Lottery.PlayTypes.BuDingWeiDan = function (name) {
    this.PlayTypeName = '';
    this.PlayTypeID = -1;
    this.Names = ["不定位"];
    if (name != null && name != '')
        this.Names = [name];
    this.Min = 0;
    this.Max = 9;
    this.HasInputModel = false; //是否具有手动输入的功能
    this.Flag = true; //是否有筛选器
    this.InputNums = []; //手工输入的号码
    this.ChoseNums = [];
    this.ChoseNums["不定位"] = "";
    this.ChoseNums[name] = '';
    this.AddChoseNums = function (id, number) {
        this.ChoseNums[id] += number;
    };
    this.RemoveChoseNums = function (id, number) {
        this.ChoseNums[id] = this.ChoseNums[id].replace(number, '');
    };
    this.GetNumsCount = function() { //获取购买号码的注数
        var value = this.ChoseNums[this.Names[0]];
        if (value == '') {
            return 0;
        }
        value = value.replace(/ /g, '');
        return value.length;
    };
};
////////////////11选5直选////////////////
Site.Lottery.PlayTypes.TC11X5_ZhiXuan = function (NameList) {
    this.IsTC11X5 = true;
    this.NumberLength = NameList.length; //单式号码的长度
    this.InputChar = ','; //手工输入的号码的分隔字符
    this.PlayTypeName = '';
    this.PlayTypeID = -1;
    this.Names = NameList;
    this.Min = 1;
    this.Max = 11;
    this.HasInputModel = true; //是否具有手动输入的功能
    this.Flag = true; //是否有筛选器
    this.InputNums = []; //手工输入的号码
    this.ChoseNums = [];
    for (var i = 0; i < this.Names.length; i++) {
        this.ChoseNums[this.Names[i]] = '';
    }
    this.AddChoseNums = function (id, number) {
        if (number == '') {
            return;
        }
        if (number.length == 1) {
            number = '0' + number;
        }
        if (this.ChoseNums[id] == '') {
            this.ChoseNums[id] = number;
        } else {
            this.ChoseNums[id] += ',' + number;
        }
    };
    this.RemoveChoseNums = function (id, number) {
        if (number == '') {
            return;
        }
        if (number.length == 1) {
            number = '0' + number;
        }
        if (this.ChoseNums[id].indexOf(number + ',') >= 0) {
            this.ChoseNums[id] = this.ChoseNums[id].replace(number + ',', '');
        } else if (this.ChoseNums[id].indexOf(',' + number) >= 0) {
            this.ChoseNums[id] = this.ChoseNums[id].replace(',' + number, '');
        } else {
            this.ChoseNums[id] = this.ChoseNums[id].replace(number, '');
        }
    };
    this.GetNumsCount = function() { //获取购买号码的注数
        if (this.InputNums.length != 0) {
            return this.InputNums.length;
        }
        var count = 0;

        var List = new Array();
        for (var i = 0; i < this.Names.length; i++) {
            var str = this.ChoseNums[this.Names[i]];
            List[i] = str;
        }
        if (this.Names.length == 3) {
            for (var i = 0; i < List[0].split(',').length; i++) {
                for (var j = 0; j < List[1].split(',').length; j++) {
                    for (var k = 0; k < List[2].split(',').length; k++) {
                        if (List[0].split(',')[i].toString() != List[1].split(',')[j].toString() && List[0].split(',')[i].toString() != List[2].split(',')[k].toString() && List[1].split(',')[j].toString() != List[2].split(',')[k].toString())
                            count += 1;
                    }
                }
            }
            if (List[2] == "" || List[1] == "" || List[0] == "") {
                return 0;
            } else {
                return count;
            }

        } else if (this.Names.length == 2) {
            for (var i = 0; i < List[0].split(',').length; i++) {
                for (var j = 0; j < List[1].split(',').length; j++) {
                    if (List[0].split(',')[i].toString() != List[1].split(',')[j].toString())
                        count += 1;
                }
            }
            if (List[1] == "" || List[0] == "") {
                return 0;
            } else {
                return count;
            }
        }

    };
};

////////////////11选5组选////////////////
Site.Lottery.PlayTypes.TC11X5_ZuXuan = function (name, type) {
    this.IsTC11X5 = true;
    this.NumberLength = 0; //单式号码的长度
    this.InputChar = ' '; //手工输入的号码的分隔字符
    this.PlayTypeName = '';
    this.PlayTypeID = -1;
    this.Names = [name];
    this.Min = 1;
    this.Max = 11;
    this.Type = type;
    this.HasInputModel = true; //是否具有手动输入的功能
    this.Flag = true; //是否有筛选器
    this.InputNums = []; //手工输入的号码
    this.ChoseNums = [];
    this.ChoseNums[this.Names] = '';
    if (type == 1) {
        this.NumberLength = 3;
    } else {
        this.NumberLength = 2;
    }
    this.AddChoseNums = function (id, number) {
        if (number == '') {
            return;
        }
        if (number.length == 1) {
            number = '0' + number;
        }
        if (this.ChoseNums[id] == '') {
            this.ChoseNums[id] = number;
        } else {
            this.ChoseNums[id] += ',' + number;
        }
    };
    this.RemoveChoseNums = function (id, number) {
        if (number == '') {
            return;
        }
        if (number.length == 1) {
            number = '0' + number;
        }
        if (this.ChoseNums[id].indexOf(number + ',') >= 0) {
            this.ChoseNums[id] = this.ChoseNums[id].replace(number + ',', '');
        } else if (this.ChoseNums[id].indexOf(',' + number) >= 0) {
            this.ChoseNums[id] = this.ChoseNums[id].replace(',' + number, '');
        } else {
            this.ChoseNums[id] = this.ChoseNums[id].replace(number, '');
        }
    };
    this.GetNumsCount = function() { //获取购买号码的注数
        if (this.InputNums.length != 0) {
            return this.InputNums.length;
        }
        var count = 0;
        var str = this.ChoseNums[this.Names[0]];
        if (str == '') {
            return 0;
        }
        var numCount = [];
        if (this.Type == 1)
            numCount = [0, 0, 0, 1, 4, 10, 20, 35, 56, 84, 120, 165];
        else
            numCount = [0, 0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55];
        count = numCount[str.split(',').length];
        return count;
    };
};

////////////////11选5任选////////////////
Site.Lottery.PlayTypes.TC11X5_Chose = function (name, type) {
    this.IsChose = true;
    this.IsTC11X5 = true;
    this.NumberLength = parseInt(type); //单式号码的长度
    this.InputChar = ' '; //手工输入的号码的分隔字符
    this.PlayTypeName = '';
    this.PlayTypeID = -1;
    this.Names = [name];
    this.Min = 1;
    this.Max = 11;
    this.Type = type;
    this.HasInputModel = true; //是否具有手动输入的功能
    this.Flag = true; //是否有筛选器
    this.InputNums = []; //手工输入的号码
    this.ChoseNums = [];
    this.ChoseNums[this.Names] = '';
    this.AddChoseNums = function (id, number) {
        if (number == '') {
            return;
        }
        if (number.length == 1) {
            number = '0' + number;
        }
        if (this.ChoseNums[id] == '') {
            this.ChoseNums[id] = number;
        } else {
            this.ChoseNums[id] += ',' + number;
        }
    };
    this.RemoveChoseNums = function (id, number) {
        if (number == '') {
            return;
        }
        if (number.length == 1) {
            number = '0' + number;
        }
        if (this.ChoseNums[id].indexOf(number + ',') >= 0) {
            this.ChoseNums[id] = this.ChoseNums[id].replace(number + ',', '');
        } else if (this.ChoseNums[id].indexOf(',' + number) >= 0) {
            this.ChoseNums[id] = this.ChoseNums[id].replace(',' + number, '');
        } else {
            this.ChoseNums[id] = this.ChoseNums[id].replace(number, '');
        }
    };
    this.GetNumsCount = function() { //获取购买号码的注数
        if (this.InputNums.length != 0) {
            return this.InputNums.length;
        }
        var str = this.ChoseNums[this.Names[0]];
        if (str == '') {
            return 0;
        }
        var count = 0;
        var numCount = [];
        if (this.Type == 1) {
            return str.split(',').length;
        } else if (this.Type == 2) {
            numCount = [0, 0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55];
        } else if (this.Type == 3) {
            numCount = [0, 0, 0, 1, 4, 10, 20, 35, 56, 84, 120, 165];
        } else if (this.Type == 4) {
            numCount = [0, 0, 0, 0, 1, 5, 15, 35, 70, 126, 210, 330];
        } else if (this.Type == 5) {
            numCount = [0, 0, 0, 0, 0, 1, 6, 21, 56, 126, 252, 462];
        } else if (this.Type == 6) {
            numCount = [0, 0, 0, 0, 0, 0, 1, 7, 28, 84, 210, 462];
        } else if (this.Type == 7) {
            numCount = [0, 0, 0, 0, 0, 0, 0, 1, 8, 36, 120, 330];
        } else if (this.Type == 8) {
            numCount = [0, 0, 0, 0, 0, 0, 0, 0, 1, 9, 45, 165];
        }
        count = numCount[str.split(',').length];
        return count;
    };
};
////////////////好彩1////////////////
Site.Lottery.PlayTypes.HC1 = function() {
    this.PlayTypeName = '';
    this.PlayTypeID = -1;
    this.ChoseNums = '';
    this.AddChoseNums = function(number) {
        if (number == '') {
            return;
        }
        if (this.ChoseNums == '') {
            this.ChoseNums = number;
        } else {
            this.ChoseNums += ',' + number;
        }
    };
    this.RemoveChoseNums = function(number) {
        if (number == '') {
            return;
        }
        if (this.ChoseNums.indexOf(number + ',') >= 0) {
            this.ChoseNums = this.ChoseNums.replace(number + ',', '');
        } else if (this.ChoseNums.indexOf(',' + number) >= 0) {
            this.ChoseNums = this.ChoseNums.replace(',' + number, '');
        } else {
            this.ChoseNums = this.ChoseNums.replace(number, '');
        }
    };
    this.GetNumsCount = function() { //获取购买号码的注数
        if (this.ChoseNums == '') {
            return 0;
        }
        return this.ChoseNums.split(',').length;
    };
};
/////////////////北京快乐8-快乐选号//////////////////
Site.Lottery.PlayTypes.ChoseNum = function() {
    this.PlayTypeName = '';
    this.PlayTypeID = -1;
    this.ChoseNums = '';
    this.AddChoseNums = function(number) {
        if (number == '') {
            return;
        }
        if (number.length == 1) {
            number = '0' + number;
        }
        if (this.ChoseNums == '') {
            this.ChoseNums = number;
        } else {
            this.ChoseNums += ',' + number;
        }
    }
    this.RemoveChoseNums = function(number) {
        if (number == '') {
            return;
        }
        if (number.length == 1) {
            number = '0' + number;
        }
        if (this.ChoseNums.indexOf(number + ',') >= 0) {
            this.ChoseNums = this.ChoseNums.replace(number + ',', '');
        } else if (this.ChoseNums.indexOf(',' + number) >= 0) {
            this.ChoseNums = this.ChoseNums.replace(',' + number, '');
        } else {
            this.ChoseNums = this.ChoseNums.replace(number, '');
        }
    };
    this.GetNumsCount = function() { //获取购买号码的注数
        if (this.ChoseNums == '') {
            return 0;
        }
        return 1;
    };
};
/////////////////北京快乐8-和值玩法//////////////////
Site.Lottery.PlayTypes.HeZhi = function() {
    this.PlayTypeName = '';
    this.PlayTypeID = -1;
    this.ChoseNums = '';
    this.AddChoseNums = function(number) {
        if (number == '') {
            return;
        }
        this.ChoseNums += number;
    };
    this.RemoveChoseNums = function(number) {
        if (number == '') {
            return;
        }
        this.ChoseNums = this.ChoseNums.replace(number, '');
    };
    this.GetNumsCount = function() { //获取购买号码的注数
        if (this.ChoseNums == '') {
            return 0;
        }
        return this.ChoseNums.length;
    };
};
/////////////////北京快乐8-龙虎玩法//////////////////
Site.Lottery.PlayTypes.LongFu = function() {
    this.PlayTypeName = '';
    this.PlayTypeID = -1;
    this.ChoseNums = '';
    this.AddChoseNums = function(number) {
        if (number == '') {
            return;
        }
        this.ChoseNums += number;
    };
    this.RemoveChoseNums = function(number) {
        if (number == '') {
            return;
        }
        this.ChoseNums = this.ChoseNums.replace(number, '');
    };
    this.GetNumsCount = function() { //获取购买号码的注数
        if (this.ChoseNums == '') {
            return 0;
        }
        return this.ChoseNums.length;
    };
};
Site.Lottery.PlayTypes.CheckNumber = function(txt, obj) {
    var regReplace = /[ \r\n\t;,]/;
    var list = txt.split(regReplace);
    var length = obj.Names.length;
    var reg = /^\d+$/;
    for (var i = 0; i < list.length; i++) {
        if (reg.test(list[i]) && list[i].length == length) {
            obj.InputNums = obj.InputNums.concat(list[i].split('').join(','));
        }
    }
};
Site.Lottery.PlayTypes.CheckNumber2 = function(txt, obj) {
    var regReplace = /[\r\n]/;
    var list = txt.split(regReplace);
    var reg = /^[1-9ab]$/;
    for (var i = 0; i < list.length; i++) {
        var str = list[i].toString().replace(/10/g, 'a').replace(/11/g, 'b').replace(/ /g, '').replace(/\t/g, '').replace(/;/g, '').replace(/,/g, '').replace(/0/g, '');
        //验证
        if (str.length != obj.NumberLength) {
            continue;
        }
        var flag = true;
        for (j = 0; j < str.length; j++) {
            var s = str.substr(j, 1);
            if (!reg.test(s)) {
                flag = false;
                break;
            }
            if (obj.IsChose && str.replace(s, '').replace(s, '').length < str.length - 1) {
                flag = false;
                break;
            }
        }
        if (!flag) {
            continue;
        }
        var list2 = str.split('');
        for (j = 0; j < list2.length; j++) {
            if (list2[j] != 'a' && list2[j] != 'b') {
                list2[j] = '0' + list2[j];
            }
        }
        var num = list2.join(obj.InputChar);
        obj.InputNums = obj.InputNums.concat(num.replace(/a/g, '10').replace(/b/g, '11'));
    }
};
function Sort(nums) {
    var maxNumber = _ParseInt(nums[nums.length - 1]);
    var index = -1;
    for (var i = nums.length - 1; i > 0; i--) {
        for (var j = i - 1; j >= 0; j--) {
            var temp = _ParseInt(nums[j]);
            if (maxNumber < temp) {
                index = j;
                maxNumber = temp;
            }
        }
        if (index != -1) {
            nums[index] = nums[i];
            nums[i] = maxNumber < 10 ? '0' + maxNumber : '' + maxNumber;
            index = -1;
        }
        maxNumber = _ParseInt(nums[i - 1]);
    }
    return nums;
}
                
            